/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.mes.base.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.springblade.modules.mes.base.entity.MaterialInfo;
import org.springblade.modules.mes.base.entity.PrdBom;
import org.springblade.modules.mes.base.vo.PrdBomVO;
import org.springblade.modules.mes.base.vo.ScanItemVO;

import java.util.List;
import java.util.Map;

/**
 * 产品BOM信息 Mapper 接口
 *
 * @author BladeX
 * @since 2021-03-12
 */
public interface PrdBomMapper extends BaseMapper<PrdBom> {

	/**
	 * 自定义分页
	 *
	 * @param page
	 * @param prdBom
	 * @return
	 */
	List<PrdBomVO> selectPrdBomPage(IPage page, @Param("prdBom") PrdBomVO prdBom);

	/**
	 * 删除bom
	 * @return
	 */
	boolean deleteBoms(List<String> deleteTopPrdNos, List<String> deleteBomAndSubPrdNos);

	/**
	 * BOM详情
	 * @param id
	 * @return
	 */
	PrdBomVO getDetail(String id);

	/**
	 * 查询某个产品的直接下级列表
	 * @param prdBom
	 * @return
	 */
	List<PrdBomVO> selectChildPrdBomList(PrdBomVO prdBom);

	/**
	 * 根据顶级编码查询一个完整BOM
	 * @param topProductNo
	 * @return
	 */
	List<PrdBomVO> listByTopNo(@Param("topProductNo") String topProductNo, @Param("tenantId") String tenantId);

	/**
	 * 生产接口获取所有有bom的产品信息
	 */
	List<PrdBomVO> getBomList(@Param("entity") PrdBomVO prdBomVO);

	/**
	 * 生产接口获取产品下一层bom所有信息
	 */
	List<PrdBomVO> getMaterialListByLeaderNo(@Param("entity") PrdBomVO prdBomVO);

	List<PrdBomVO> getUnConnectList();

	/**
	 *生产接口获取所有辅料
	 */
	List<PrdBomVO> getAMList(String tenantId);


	/**
	 * 生产接口根据产品编号获取产品信息
	 */
	List<MaterialInfo> getMaterialList(List<String> list);


	void deleteBomByTopProductNo(@Param("materialNo") String materialNo);

    List<Map<String, Object>> getBomByProductId(@Param("productId") Long productId);

	List<Map<String, Object>> getProductId(@Param("productId") Long productId);

	boolean deleteByIds(@Param("ids") List<Long> ids);

    void updateStatusByProduceNo(@Param("materialNo") String materialNo, @Param("approver") String approver, @Param("processInstanceId") String processInstanceId, @Param("processDefinitionId") String processDefinitionId, @Param("status") int status);

    List<String> getParent(@Param("materialNo") String materialNo);

	int getBomStatus(@Param("productNo") String productNo);

	void deleteBomBySupAndMaterialNo(@Param("directLeaderNos") List<String> directLeaderNos, @Param("materialNos") List<String> materialNos);

	List<PrdBomVO> getAllTopProductBomList();

	List<PrdBomVO> getAllBomList();

	List<PrdBomVO> getTopProductBomList(@Param("productNoList") List<String> productNoList);

    List<PrdBomVO> listParent(@Param("productNo") String productNo, @Param("tenantId") String tenantId);

    List<PrdBomVO> selectQuota(@Param("productNo") String productNo, @Param("tenantId") String tenantId);

    List<PrdBomVO> getByProductionLine(@Param("productionLine") String productionLine, @Param("materialNo") String materialNo, @Param("formulaNo") String formulaNo);

	List<PrdBomVO> findByMaterialNos(@Param("materialNos") List<String> materialNos);

	List<ScanItemVO> findScanList(@Param("scanBarCode")String scanBarCode,@Param("assemblyNo")String assemblyNo,@Param("stationCode")String stationCode);

	List<ScanItemVO> findScanAllList(@Param("scanBarCode")String scanBarCode,@Param("assemblyNo")String assemblyNo,@Param("stationCode")String stationCode);

}
